<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>个人信息</title>
    <link rel="stylesheet" href="/static/index1.css">
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
<h2>帖子</h2>
<table id="postTable">
    <thead>
    <tr>
        <th>图片</th>
        <th>标题</th>
        <th>简介</th>
        <th>查看详情</th>
    </tr>
    </thead>
    <tbody>
    <!-- 商品列表将在这里动态生成 -->
    </tbody>
</table>
<script>
    $(document).ready(function() {
        const token = localStorage.getItem('token'); // 从 localStorage 中获取 token

        // 发送请求获取post信息
        fetch('/user/post', {
            method: 'GET',
            headers: {
                'Content-Type': 'application/json',
                'Token': token
            }
        })
            .then(response => response.json())
            .then(data => {
                console.log("这是传回数据信息",data.data)
                if (data.code === 0) {
                    const tbody = document.querySelector('#postTable tbody');
                    tbody.innerHTML = ''; // 清空之前的商品列表
                    data.data.forEach(post => {
                        const row = document.createElement('tr');

// 图片
                        const photoCell = document.createElement('td');
                        const imgElement = document.createElement('img');
                        imgElement.src = post.imageurl;
                        imgElement.style.maxWidth = '200px'; // 例如，设置最大宽度
                        imgElement.style.maxHeight = '120px'; // 例如，设置最大高度
                        photoCell.appendChild(imgElement);
                        row.appendChild(photoCell);

// 标题
                        const titleCell = document.createElement('td');
                        titleCell.textContent = post.title;
                        row.appendChild(titleCell);

// 简介
                        const briefCell = document.createElement('td');
                        briefCell.textContent = post.brief;
                        row.appendChild(briefCell);


//创建新的一列
                        const actionButtonCell = document.createElement('td');
// 查看卖家信息按钮
                        const moreButton = document.createElement('button');
                        moreButton.textContent = '展开';
                        moreButton.onclick = function() {
                            window.location.href = `/api/v1/post/searchpidHTML?id=${post.pid}`; // 假设详情页HTML
                        };
                        actionButtonCell.appendChild(moreButton);
                        actionButtonCell.appendChild(document.createTextNode(' ')); // 添加间隔


                        row.appendChild(actionButtonCell);

// 将行添加到表格中
                        tbody.appendChild(row);
                    });
                } else {
                    alert('获取post信息失败: ' + data.msg);
                }
            })
            .catch(error => {
                console.error('Error:', error);
                alert('请求失败');
            });
    });
</script>
</body>
</html>